// in param representation
filter2: '1', filter3: '1',
// Group type string_options
- group2: 'filter4',
+ group2: 'filter4'
// Note - Group3 is sticky, so it won't show in output
- // highlight toggle
- highlight: '1'
},
highlights: {
group1__filter1_color: 'c5',
}
}
}
+ },
+ removeHighlights = function ( data ) {
+ var copy = $.extend( true, {}, data );
+ copy.queries[ 1234 ].data.highlights = {};
+ return copy;
};
QUnit.module( 'mediawiki.rcfilters - SavedQueriesModel' );
finalState: $.extend( true, { default: '1234' }, queriesParamRepresentation ),
msg: 'Conversion from filter representation to parameters, with default set up, retains data.'
},
+ {
+ // Converting from old structure and cleaning up highlights
+ input: $.extend( true, queriesFilterRepresentation, { queries: { 1234: { data: { highlights: { highlight: false } } } } } ),
+ finalState: removeHighlights( queriesParamRepresentation ),
+ msg: 'Conversion from filter representation to parameters and highlight cleanup'
+ },
{
// New structure
input: $.extend( true, {}, queriesParamRepresentation ),
input: $.extend( true, { queries: { 1234: { data: { highlights: { group2__filter5_color: 'c2' } } } } }, exampleQueryStructure ),
finalState: $.extend( true, { queries: { 1234: { data: { highlights: { group2__filter5_color: 'c2' } } } } }, exampleQueryStructure ),
msg: 'Structure that contains invalid highlights remains the same in initialization'
+ },
+ {
+ // Trim colors when highlight=false is stored
+ input: $.extend( true, { queries: { 1234: { data: { params: { highlight: '0' } } } } }, queriesParamRepresentation ),
+ finalState: removeHighlights( queriesParamRepresentation ),
+ msg: 'Colors are removed when highlight=false'
+ },
+ {
+ // Remove highlight when it is true but no colors are specified
+ input: $.extend( true, { queries: { 1234: { data: { params: { highlight: '1' } } } } }, removeHighlights( queriesParamRepresentation ) ),
+ finalState: removeHighlights( queriesParamRepresentation ),
+ msg: 'remove highlight when it is true but there is no colors'
}
];
label: 'label2',
data: {
params: {
- filter1: '1',
- invert: '1'
+ filter1: '1' // Invert will be dropped because there are no namespaces
},
highlights: {
group1__filter1_color: 'c3'
'New query 1',
{
group2: 'filter5',
- highlight: '1',
group1__filter1_color: 'c5',
group3__group3option1_color: 'c1'
}
label: 'New query 1',
data: {
params: {
- group2: 'filter5',
- highlight: '1'
+ group2: 'filter5'
},
highlights: {
group1__filter1_color: 'c5',
data: {
params: {
filter1: '1',
- filter2: '1',
- invert: '1'
+ filter2: '1'
},
highlights: {}
}
// Find matching query
matchingItem = queriesModel.findMatchingQuery(
{
- highlight: '1',
group2: 'filter5',
group1__filter1_color: 'c5',
group3__group3option1_color: 'c1'
group2: 'filter5',
filter1: '0',
filter2: '0',
- highlight: '1',
- invert: '0',
group1__filter1_color: 'c5',
group3__group3option1_color: 'c1'
}
'Finding matching item by "dirty" state with 0-base values'
);
} );
+
+ QUnit.test( 'Testing invert property', function ( assert ) {
+ var itemID, item,
+ filtersModel = new mw.rcfilters.dm.FiltersViewModel(),
+ queriesModel = new mw.rcfilters.dm.SavedQueriesModel( filtersModel ),
+ viewsDefinition = {
+ namespace: {
+ label: 'Namespaces',
+ trigger: ':',
+ groups: [ {
+ name: 'namespace',
+ label: 'Namespaces',
+ type: 'string_options',
+ separator: ';',
+ filters: [
+ { name: 0, label: 'Main', cssClass: 'namespace-0' },
+ { name: 1, label: 'Talk', cssClass: 'namespace-1' },
+ { name: 2, label: 'User', cssClass: 'namespace-2' },
+ { name: 3, label: 'User talk', cssClass: 'namespace-3' }
+ ]
+ } ]
+ }
+ };
+
+ filtersModel.initializeFilters( filterDefinition, viewsDefinition );
+
+ // Start with an empty saved queries model
+ queriesModel.initialize( {} );
+
+ filtersModel.toggleFiltersSelected( {
+ group1__filter3: true,
+ invertGroup__invert: true
+ } );
+ itemID = queriesModel.addNewQuery(
+ 'label1', // Label
+ filtersModel.getMinimizedParamRepresentation(),
+ true, // isDefault
+ '2345' // ID
+ );
+ item = queriesModel.getItemByID( itemID );
+
+ assert.deepEqual(
+ item.getState(),
+ {
+ label: 'label1',
+ data: {
+ params: {
+ filter1: '1',
+ filter2: '1'
+ },
+ highlights: {}
+ }
+ },
+ 'Invert parameter is not saved if there are no namespaces.'
+ );
+
+ // Reset
+ filtersModel.initializeFilters( filterDefinition, viewsDefinition );
+ filtersModel.toggleFiltersSelected( {
+ group1__filter3: true,
+ invertGroup__invert: true,
+ namespace__1: true
+ } );
+ itemID = queriesModel.addNewQuery(
+ 'label1', // Label
+ filtersModel.getMinimizedParamRepresentation(),
+ true, // isDefault
+ '1234' // ID
+ );
+ item = queriesModel.getItemByID( itemID );
+
+ assert.deepEqual(
+ item.getState(),
+ {
+ label: 'label1',
+ data: {
+ params: {
+ filter1: '1',
+ filter2: '1',
+ invert: '1',
+ namespace: '1'
+ },
+ highlights: {}
+ }
+ },
+ 'Invert parameter saved if there are namespaces.'
+ );
+ } );
}( mediaWiki ) );